<?php
  include("../Includes/FusionCharts_Gen.php");
  include("../Includes/DBConn.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
	<HEAD>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>UPLB DV</title>
		
		<script language="Javascript" src="../js/FusionCharts.js"></script>
		<script type="text/javascript" src="../fancybox/jquery.min.js"></script>
		<script type="text/javascript" src="../fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
		<script type="text/javascript" src="../fancybox/jquery.fancybox-1.3.4.pack.js"></script>
		

		<link rel="stylesheet" href="../fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />

	</HEAD>

	<BODY>
	<CENTER>
			<?php
				$courseCode = $_GET['courseCode'];
				if($courseCode=="default"){
					$subject = "CMSC 11";
					$AY = 2007;
					
				}
				else{
					$subject = $_POST['subject'];
					$AY = $_POST['AY'];
				}
				
				$endAY = $AY + 1;
				
				$FC = new FusionCharts("Column3D","800","500");
				$FC->setSwfPath("../FusionCharts/");
				$strParam="caption=$subject Grade Distribution;subcaption=AY $AY-$endAY;xAxisName=Grades;yAxisName=Frequency;formatNumberScale=0;decimalPrecision=0";
				$FC->setChartParams($strParam);
				$link = connectToDB();
				
				if($subject!=""){
					$strQuery = "select grade_1_00 from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_1_00'], 'name=1.00');
					}
					
					$strQuery = "select grade_1_25 from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());			
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_1_25'], 'name=1.25');
					}
					
					$strQuery = "select grade_1_50 from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_1_50'], 'name=1.50');
					}
					
					$strQuery = "select grade_1_75 from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());			
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_1_75'], 'name=1.75');
					}
					
					$strQuery = "select grade_2_00 from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_2_00'], 'name=2.00');
					}
					
					$strQuery = "select grade_2_25 from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());			
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_2_25'], 'name=2.25');
					}
					
					$strQuery = "select grade_2_50 from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_2_50'], 'name=2.50');
					}
					
					$strQuery = "select grade_2_75 from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());			
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_2_75'], 'name=2.75');
					}
					
					$strQuery = "select grade_3_00 from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_3_00'], 'name=3.00');
					}
					
					$strQuery = "select grade_4_00 from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());			
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_4_00'], 'name=4.00');
					}
					
					$strQuery = "select grade_5_00 from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_5_00'], 'name=5.00');
					}
					
					$strQuery = "select grade_S from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());			
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_S'], 'name=S');
					}
					
					$strQuery = "select grade_U from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_U'], 'name=U');
					}
					
					$strQuery = "select grade_DRP from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());			
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_DRP'], 'name=DRP');
					}
					
					$strQuery = "select grade_INC from course where academicYear='$AY' and courseCode='$subject'"; 
					$result = mysql_query($strQuery) or die(mysql_error());
					if ($result) 
					{
						$ors = mysql_fetch_array($result);
						$FC->addChartData($ors['grade_INC'], 'name=INC');
					}
					
				}
				mysql_close($link);
				$FC->renderChart();
			?>
	</CENTER>
	</BODY>
</HTML>